package com.baizhi.travels.service.impl;

import com.baizhi.travels.mapper.UserDao;
import com.baizhi.travels.entity.User;
import com.baizhi.travels.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Description:travels
 * Created by admin  on 2020/5/19  17:24
 */
@Service
@Transactional
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public void register(User user) {
        userDao.save(user);
    }

    @Override
    public User login(User user) {

        User userDB = userDao.findByUsername(user.getUsername());
        if (userDB != null){
            if (userDB.getPassword().equals(user.getPassword())){
                return userDB;
            }
            throw new RuntimeException("密码输入错误");
        }else {
            throw new RuntimeException("用户名错误");
        }
    }
}
